'use strict';

const { getData, getMultiData } = require('../lib/data.js');
const { Card, getCard } = require('../lib/cardNode.js');

const Controller = require('egg').Controller;

class CardController extends Controller {
  async index() {
    const { ctx } = this;
    const id = ctx.query.id;
    
    let res = await getData(id);
    ctx.body = res;
  }


  async multi() {
    const { ctx } = this;
    const ids = ctx.query.ids;
    
    let res = await getMultiData(ids);
    ctx.body = res;
  }


  async card() {
    const { ctx } = this;
    const id = ctx.query.id;
    const size = parseInt(ctx.query.size);
    let data = await getData(id);
    data = Card.transData(data);

    const card = await getCard(data, {
      size: size,
      moldPath: './app/public/mold/',
      picPath: `./app/public/pics/500/${id}.jpg`,
    });
    
    ctx.body = card;
    ctx.set('Content-Type', 'image/jpg');
  }
}

module.exports = CardController;
